package HW1;

import java.util.List;
import java.util.Scanner;

/*
    添加新的学生
    需要输入学号，姓名，年龄
 */
public class AddStudents {
    //Student st = new Student();
    public AddStudents() {
    }
    static void add(List<Student> list){
        Scanner sc = new Scanner(System.in);

        System.out.println("请输入要添加的学生的学号"); String s = sc.nextLine();
        System.out.println("请输入要添加的学生的姓名"); String s1 = sc.nextLine();
        System.out.println("请输入要添加的学生的年龄"); int s2 = sc.nextInt();
        for(Student st: list){
            if(st.getId().equals(s)){
                System.out.println("已经存在该学号，无效！！");
                return;
            }
        }
        Student stu = null;
        try {
            stu = new Student(s,s1,s2);
            //添加student的对象到list中
            list.add(stu);
            System.out.println("添加成功");
        } catch (StudentAgeException e) {
            e.printStackTrace();
        } catch (StudentIDException e) {
            e.printStackTrace();
        }

    }
}
